<!--suppress ALL -->
<div class="layui-fluid layui-anim website-anim" id="website-topic-plan" lay-title="课题计划管理"
     xmlns:th="http://www.w3.org/1999/xhtml">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="topic-plan-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">年份</label>
                                        <div class="layui-input-inline">
                                            <input type="text" class="layui-input" id="topicPlanYearSearch" readonly
                                                   name="year">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-green-plain table-action"
                                     id="reset">
                                    重置
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="add">
                                    添加
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="topicPlanTable" lay-data="{id: 'topicPlanTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!--表格中的操作栏-->
<script type="text/html" id="topic-plan-option">
    <span shiro:lacksPermission="topicPlan:list,topicPlan:update,topicPlan:delete">
        <span class="layui-badge-dot website-bg-orange"></span> 无权限
    </span>
    <a lay-event="detail" class="website-green" shiro:hasPermission="topicPlan:list">详情</a>
    <a lay-event="download" class="{{ d.isGenerateCode?'':'website-hide'}} website-blue"
       shiro:hasPermission="topicPlan:list">导出</a>
    <a lay-event="distribution" class=" {{ d.isGenerateCode?'website-hide':''}} website-orange "
       shiro:hasPermission="topicPlan:list">分配专家</a>
    <a lay-event="result" class="website-green" shiro:hasPermission="topicPlan:list">评审结果</a>
</script>

<script type="text/html" id="publish-unit">
    <span>中国法学会</span>
</script>


<script data-th-inline="none" type="text/javascript">
    layui.use(['jquery', 'form', 'table', 'website', 'laydate'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            $view = $('#website-topic-plan'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $add = $view.find('#add'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns;
        form.render();
        initTable();
        //初始化年份的搜索框
        laydate.render({
            elem: '#topicPlanYearSearch', //指定元素
            type: 'year',
            trigger: 'click',
        });
        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(topicPlanTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                website.navigate(ctx + "biz/topic/" + data.planId + "?refresh=true");
            }
            if (layEvent === 'download') {
                website.download(ctx + 'biz/topic/word/' + data.planId, null, '课题指南信息表.docx');
            }
            if (layEvent === 'distribution') {
                website.navigate(ctx + "biz/distribution/" + data.planId + "/" + data.year);
            }
            if (layEvent === 'result') {
                website.navigate(ctx + "biz/distribution/result/" + data.planId);
            }
        });

        /**
         * 表格的排序点击
         **/
        table.on('sort(topicPlanTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

        /**
         * 添加
         */
        $add.on('click', function () {
            website.modal.open('新增课题计划', 'biz/topicPlan/add/', {
                btn: ['提交', '重置'],
                area: $(window).width() <= 750 ? '50%' : '30%',
                offset: '30%',
                yes: function (index, layero) {
                    $('#topicPlan-add').find('#submit').trigger('click');
                },
                btn2: function () {
                    $('#topicPlan-add').find('#reset').trigger('click');
                    return false;
                }
            });

        });

        /**
         * 初始化表格
         */
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'topicPlanTable',
                url: ctx + 'biz/topicPlan/list',
                where: {topicClassifyCode: 'annual'},
                cols: [[
                    /*{type: 'checkbox'},*/
                    /* { type: 'numbers', title: '序号', },*/
                    {field: 'year', title: '年份', minWidth: 100},
                    {title: '发布单位', templet: '#publish-unit'},
                    {title: '操作', toolbar: '#topic-plan-option', minWidth: 140}
                ]]
            });
        }

        /**
         * 获取查询条件
         * @returns {{}}
         */
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            return params;
        }

    })
</script>